package com.jxw.adapter;

import android.content.ContentValues;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import com.jxw.constant.Constant;
import com.jxw.database.QuanXianDatabaseHelper;
import com.jxw.launcher.R;
import java.util.List;
import java.util.Map;

/* loaded from: classes.dex */
public class QuanXianAdapter extends BaseAdapter {
    private static final String allow_action = "com.twd.allow.install.apps";
    private static final String no_allow_action = "com.twd.notallow.install.apps";
    private QuanXianDatabaseHelper dbDatabaseHelper;
    private ViewHolder holder;
    private String[] keyString;
    private Context mContext;
    private LayoutInflater mInflater;
    private List<Map<String, Object>> mList;
    private boolean[] selected;
    private String setname;
    private int[] valueViewID;

    @Override // android.widget.Adapter
    public long getItemId(int i) {
        return i;
    }

    public QuanXianAdapter(Context context, List<Map<String, Object>> list, int i, String[] strArr, int[] iArr) {
        this.selected = null;
        this.mContext = context;
        this.mList = list;
        this.mInflater = (LayoutInflater) this.mContext.getSystemService("layout_inflater");
        this.keyString = new String[strArr.length];
        this.valueViewID = new int[iArr.length];
        System.arraycopy(strArr, 0, this.keyString, 0, strArr.length);
        System.arraycopy(iArr, 0, this.valueViewID, 0, iArr.length);
        this.dbDatabaseHelper = new QuanXianDatabaseHelper(this.mContext);
        List<Map<String, Object>> list2 = this.mList;
        if (list2 != null) {
            this.selected = new boolean[list2.size()];
        }
    }

    @Override // android.widget.Adapter
    public int getCount() {
        return this.mList.size();
    }

    @Override // android.widget.Adapter
    public Object getItem(int i) {
        return this.mList.get(i);
    }

    @Override // android.widget.Adapter
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view != null) {
            this.holder = (ViewHolder) view.getTag();
        } else {
            this.holder = new ViewHolder();
            view = this.mInflater.inflate(R.layout.item_quanxian, (ViewGroup) null);
            this.holder.tV = (TextView) view.findViewById(this.valueViewID[0]);
            this.holder.iBtn = (ImageButton) view.findViewById(this.valueViewID[1]);
            view.setTag(this.holder);
        }
        Map<String, Object> map = this.mList.get(i);
        if (map != null) {
            this.setname = (String) map.get(this.keyString[0]);
            this.holder.tV.setText(this.setname);
            List<Map<String, Object>> queryInfo = this.dbDatabaseHelper.queryInfo(this.setname);
            if (queryInfo.size() == 0) {
                ContentValues contentValues = new ContentValues();
                contentValues.put(Constant.SETNAME, this.setname);
                contentValues.put(Constant.CHECKED, "0");
                this.dbDatabaseHelper.insertRow(contentValues);
            } else if ("1".equals((String) queryInfo.get(0).get(Constant.CHECKED))) {
                this.selected[i] = true;
            } else {
                this.selected[i] = false;
            }
            if (this.selected[i]) {
                this.holder.iBtn.setImageResource(R.drawable.selectbox_nor);
            } else {
                this.holder.iBtn.setImageResource(R.drawable.selectbox_per);
            }
        }
        this.holder.iBtn.setTag(Integer.valueOf(i));
        this.holder.iBtn.setOnClickListener(new iBtnListener(i));
        return view;
    }

    /* loaded from: classes.dex */
    class iBtnListener implements View.OnClickListener {
        int flag = 0;
        private int position;

        iBtnListener(int i) {
            this.position = i;
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            boolean z = !QuanXianAdapter.this.selected[this.position];
            Log.i("Tag", "==select==" + z);
            if (z) {
                this.flag = 1;
                ((ImageButton) view).setImageResource(R.drawable.selectbox_nor);
            } else {
                this.flag = 0;
                ((ImageButton) view).setImageResource(R.drawable.selectbox_per);
            }
            boolean z2 = QuanXianAdapter.this.selected[this.position];
            Map map = (Map) QuanXianAdapter.this.mList.get(this.position);
            if (map != null) {
                QuanXianAdapter quanXianAdapter = QuanXianAdapter.this;
                quanXianAdapter.setname = (String) map.get(quanXianAdapter.keyString[0]);
                QuanXianAdapter.this.dbDatabaseHelper.updateRow(QuanXianAdapter.this.setname, this.flag);
                QuanXianAdapter.this.notifyDataSetChanged();
            }
        }
    }

    /* loaded from: classes.dex */
    private class ViewHolder {
        private ImageButton iBtn;
        private TextView tV;

        private ViewHolder() {
        }
    }
}
